﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%
    var _topic = ViewData["Topic"] as TopicEntity;
    var _commandType = (CommandType)ViewData["CommandType"];
  
%>
<div class="fr-widget white-space">
    <div class="header">
        <div class="icon">
        </div>
        <span>
            <% 
                switch (_commandType)
                {
                    case CommandType.NewPost:
                        Response.Write("Chủ đề mới");
                        break;
                    case CommandType.Reply:
                    case CommandType.Quote:
                        Response.Write(string.Format("Trả lời: {0}", _topic.TopicName));

                        break;
                    case CommandType.Edit:
                        Response.Write(string.Format("Sửa bài: {0}", _topic.TopicName));

                        break;

                }
           
               
            %>
        </span>
    </div>
    <%using (Html.BeginForm("AddPost", "Forum", FormMethod.Post, new { @id = "PostF", @onRequest = "$.MvcForum.showLoading()", @onSuccess = "$.MvcForum.hideLoading();$.MvcForum.ajaxSuccess(msg);" }))
      { %>
    <%=Html.AntiForgeryTokenX("POST") %>
    <input type="hidden" value="<%=ViewData["sessionId"] %>" id="cmd" name="cmd" />
    <table cellpadding="0" cellspacing="1" width="100%">
        <% if ((ForumContext.UserInfo.IsAdmin || ForumContext.UserInfo.Permissions.AllowPriority))
           {%>
        <tr>
            <td class="table-cell">
                <%=ForumContext.GetText("POST", "PRIORITY")%>
            </td>
            <td class="table-cell">
                <%--<%=Html.DropDownList("Priority", typeof(PriorityType), _topic != null ? (PriorityType)_topic.Priority : PriorityType.Normal)%>--%>
                <select class="select" name="priority" id="priority" style="min-width: 200px" onchange="priorityChange(this.value)">
                    <%
                        foreach (int value in Enum.GetValues(typeof(PriorityType)))
                        {
                    %>
                    <option value="<%=value.ToString()%>">
                        <%= ForumContext.GetGlobalText("PRIORITY_" + Enum.GetName(typeof(PriorityType), value))%></option>
                    <%
                        }%>
                </select>
            </td>
        </tr>
        <tr class="hidden sticky-date">
            <td class="table-cell">
                <%=ForumContext.GetText("POST", "PRIORITY_DATEEXPIRE")%>
            </td>
            <td class="table-cell">
                <input type="text" name="prioritydate" id="prioritydate" class="input datepicker"
                    value="<%=_topic!=null && _topic.PriorityDate.HasValue?_topic.PriorityDate.Value:DateTime.UtcNow+TimeSpan.FromDays(365) %>" />
            </td>
        </tr>
        <%
            }%>
        <tr>
            <td class="table-cell width20">
                <%=ForumContext.GetText("POST","TOPIC_NAME") %>
            </td>
            <td class="table-cell">
                <input type="text" class="input {validate:{required:true}}" name="subject" id="subject"
                    value="<%=_topic!=null?_topic.TopicName:string.Empty %>" />
                <%-- <%=Html.TextBoxFor(x=>x.TopicName, new { @class = "input {validate:{required:true}}" })%>--%>
            </td>
        </tr>
        <% if (ForumContext.UserInfo.IsAdmin && _commandType == CommandType.NewPost)
           {%>
        <tr>
            <td class="table-cell">
                <%=ForumContext.GetText("POST","REMOTE_URL") %>
            </td>
            <td class="table-cell">
                <input type="text" class="input {validate:{url:true}}" name="remoteUrl" id="remoteUrl"
                    value="<%=_topic!=null?_topic.RemoteUrl:string.Empty %>" />
                <%--<%=Html.TextBoxFor(x=>x.RemoteUrl, new { @class = "input {validate:{url:true}}" })%>--%>
            </td>
        </tr>
        <%
            }%>
        <tr>
            <td class="table-cell valign-top">
                <%=ForumContext.GetText("POST", "MESSAGE")%>
            </td>
            <td class="table-cell">
                <textarea name="message" id="message" cols="1" rows="1" class="input tinymce {validate:{required:true,minlength:9}}"
                    style="height: 250px" mode="medium">
                    
                    <%
                        switch (_commandType)
                        {
                            case CommandType.Edit:
                                Response.Write(_topic.Message);
                                break;
                            case CommandType.Quote:
                                Response.Write(string.Format("[quote={0}]{1}\n[/quote]", _topic.UserName, _topic.Message));
                                break;
                        }
                 %>

                    </textarea>
                <%--<%=Html.TextAreaFor(x => x.Message, new { @class = "input tinymce {validate:{required:true}}", @mode = "medium", @style = "height: 250px" })%>--%>
            </td>
        </tr>
        <tr>
            <td class="table-cell">
                &nbsp;
            </td>
            <td class="table-cell">
                <input type="button" value="<%=_commandType==CommandType.Edit?ForumContext.GetText("POST","UPDATE"):ForumContext.GetText("POST","POST") %>"
                    class="button" onclick="$.MvcForum.ajaxSubmit('PostF')" />
            </td>
        </tr>
        <tr>
            <td colspan="2" class="table-caption">
                <%=ForumContext.GetText("POST", "OPTIONS")%>
            </td>
        </tr>
        <tr>
            <td class="table-cell" colspan="2">
                <fieldset>
                    <legend>
                        <%=ForumContext.GetText("POST","MESSAGE_ICON") %></legend>
                    <input type="radio" checked="checked" onclick="selectIcon(this.value)" name="Icons"
                        id="_icon_none" /><label for="_icon_none">None</label>
                    <%

                        var _Smiles = ViewData["Smiles"] as List<Smile>;
                        if (_Smiles != null)
                        {
                            foreach (var _smile in _Smiles)
                            {
                    %>
                    <input type="radio" name="Icons" id="_icon_<%=_smile.Id %>" onclick="selectIcon(this.value)"
                        value='<%=_smile.Icon %>' /><label for="_icon_<%=_smile.Id %>"><img alt="" src="<%=ForumContext.Configuration.TopicSmiles+ _smile.Icon %>" /></label>
                    <%
}
                        }

                    %>
                    <input type="hidden" name="icon" id="icon" value="" />
                </fieldset>
            </td>
        </tr>
        <tr class="hidden">
            <td class="table-cell">&nbsp;
            </td>
            <td class="table-cell">
                <input type="checkbox" id="autoparselinks" name="autoparselinks" checked="checked"
                    value="True" /><label for="autoparselinks"><%=ForumContext.GetText("POST","AUTO_PARSE_LINKS") %></label>
            </td>
        </tr>
        <tr class="hidden">
            <td class="table-caption" colspan="2">
                <%=ForumContext.GetText("POST","SUBSCRIPTION")%>
            </td>
        </tr>
        <tr class="hidden">
            <td class="table-cell">
                <%=ForumContext.GetText("POST","NOTIFICATION_TYPE")%>
            </td>
            <td class="table-cell">
                 <select class="select" name="notificationTypes" id="notificationTypes">
                        <%
                        
                            var _notificationTypes = Enum.GetValues(typeof(NotificationType));

                            foreach (int value in _notificationTypes)
                            {
                        %>
                        <option value="<%=value.ToString()%>">
                            <%= ForumContext.GetText("POST",Enum.GetName(typeof(NotificationType), value))%></option>
                        <%
}%>
                    </select>
            </td>
        </tr>
    </table>
</div>
<%
    } %>
<script type="text/javascript">
//<![CDATA[

//    window.Page_Load = function () {
//        if (!(window.MF_JS_LOADED)) {
//            setTimeout('Page_Load()', 100);
//            return;
//        }
//        $('.datepicker').datepicker({

//            yearRange: '-10:+30',
//            changeMonth: true,
//            changeYear: true

//        });

//        $.MvcForum.htmlEditor();
//    };

//    Page_Load();

    function priorityChange(_val) {
        if (_val == 2) {
            $('.sticky-date').fadeIn();
        }
        else {
            $('.sticky-date').fadeOut();

        }
    };

    function selectIcon(_val) {

        $('#icon').val(_val);

    };

    //]]>
  
</script>
